<table id="admin_staff_info" data-options="fit:true"></table>
<div id="admin_staff_toolbar" style="padding:0 10px;">
	<input class="icon-add" type="button" value="添加维护员" onclick="openAddStaffWin()"
		style="padding:3px 3px 3px 20px;border:1px #999 solid;margin:2px;border-radius:5px;"/>
	<input class="icon-removes" type="button" value="删除维护员" onclick="delStaff()"
		style="padding:3px 3px 3px 20px;border:1px #999 solid;margin:2px;border-radius:5px;"/>
	<input class="icon-reload" type="button" value="刷新" onclick="flushStaffInfo()"
		style="padding:3px 3px 3px 20px;border:1px #999 solid;margin:2px;border-radius:5px;"/>
</div>
<script>
$(function(){
	$('#admin_staff_info').datagrid({
		url:'../maintainerInfo/getAllStaff',
		loadMsg:'数据加载中...',
		fitColumns:true,
		rownumbers:true,
		striped:true,
		sortName:'mid',
		sortOrder:'asc',
		remoteSort:false,
		columns:[[
			{field:'mids',title:'',width:100,align:'center',checkbox:true},
			{field:'mid',title:'维护员编号',width:100,align:'center',sortable:true},
			{field:'mname',title:'姓名',width:100,align:'center'}, 
			{field:'mage',title:'年龄',width:100,align:'center'},
			{field:'msex',title:'性别',width:100,align:'center',formatter:function(value,rowData,rowIndex){
				if(value==1) {
					return "男";
				} else {
					return "女";
				}
			}},
			{field:'mtel',title:'电话',width:100,align:'center'}
		]],
		toolbar:"#admin_staff_toolbar"
	});
});

//添加
function addStaffInfo(){
	var mname = $.trim($("#staff_mname").val());
	var mage = $.trim($("#staff_mage").val());
	var msex = $.trim($("#staff_msex").find("option:selected").val());
	var mtel = $.trim($("#staff_mtel").val());
	
	//为空判断
	if(mname != "" && mage != "" && msex!="" && mtel!="") {
		$.post("../maintainerInfo/addStaffInfo",{"mname":mname,"mage":mage,"msex":msex,"mtel":mtel},
			function(data){
			data = parseInt($.trim(data.result ));
			if(data > 0) {
				$.messager.show({
					title:'成功提示',
					msg:'维护员信息添加成功!',
					timeout:3000,
					showType:'slide'
				});
				$("#staff_mname").val("");
				$("#staff_mage").val("");
				$("#staff_mtel").val("");
				$("#add_staff").dialog("close");
				$('#admin_staff_info').datagrid("reload");
			} else {
				$.messager.alert('错误提示','维护员信息添加失败!','error');
			}
		});
	} else {
		$.messager.show({
			title:'温馨提示',
			msg:'您输入的信息不完整，请确认后再提交!',
			timeout:3000,
			showType:'slide'
		});
	}
}

//打开添加信息窗口
function openAddStaffWin() {
	$("#add_staff").dialog("open");
}

//删除维护员信息
function delStaff() {
	var mids=$('#admin_staff_info').datagrid('getSelections');
	if(mids.length==0){
		$.messager.alert('错误提示','请选择删除项!','error');
		return;
	}
	if(mids.length>1){
		$.messager.alert('错误提示','请逐条操作!','error');
		$('#admin_staff_info').datagrid('clearSelections');
	}else{
		$.messager.defaults = {ok : "是",cancel : "否"};
		$.messager.confirm("操作提示", "您确定要执行操作吗？", function(data) {
			if (data) {
				$.post("../maintainerInfo/delStaffInfo",{"mid":mids[0].mid},function(data) {
					if (parseInt($.trim(data.result)) == 1) {
						$.messager.show({
							title : '成功提示',
							msg : '删除信息成功！',
							timeout : 3000,
							showType : 'slide'
						});
						$('#admin_staff_info').datagrid("reload");
					} else {
						$.messager.alert('错误提示', '网络错误,请稍后重试!', 'error');
					}
				});
			} else {
				$('#admin_staff_info').datagrid('clearSelections');
			}
		});
	}
}

	function flushStaffInfo() {
		$('#admin_staff_info').datagrid("reload");
	}
</script>
<div id="add_staff" class="easyui-dialog" title="添加维护员信息" style="width:400px;height:300px;"
	data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
	<p style="width:100%;text-align:center;">
		<br /> <br /> 
		<label for="staff_mname">姓名：</label><input type="text" id="staff_mname">
		<br /> <br /> 
		<label for="staff_mage">年龄：</label><input type="text" id="staff_mage">
		<br /> <br />
		<label for="staff_msex">性别：</label><select id="staff_msex" style="width:130px;">
			<option value="1">男</option>
			<option value="0">女</option>
		</select>
		<br /> <br />
		<label for="staff_mtel">电话：</label><input type="text" id="staff_mtel">
		<br /> <br />
		<span style="color:red;">维护员默认密码为：123456</span>
		<br /> <br />
		<input style="padding:5px 25px;" type="button" onclick="addStaffInfo()" value="添加">
	</p>
</div>

